import RxElement from "../../utils/RxElement";

export default class RxLoading {
  static show(text = '加载中..') {
    this._setLoading(true, text)
  }

  static hidden() {
    this._setLoading()
  }


  static _setLoading(isShow = false, text = '') {
    const loadingDiv = RxElement.getElButtonId('rxloading')
    if (!loadingDiv) {
      console.error('RxLoad loadingDiv==null')
      return
    }

    let style = 'display:'

    if (isShow) {
      try {
        const rxloading_content = loadingDiv.childNodes[1] || {}
        const rxloading_text = rxloading_content.childNodes[1] || {}
        rxloading_text.innerHTMl = text
      } catch (error) {
        console.error('RxLoad error', error)
      }
      style += 'flex'
    } else {
      style += 'none'
    }

    // console.log('RxLoad style=', style)
    loadingDiv.style = style
  }

}